package com.nlp.visualization.core.lda.process;

import com.nlp.visualization.pojo.lda.LDATheme;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.io.IOException;
import java.util.List;

/**
 * @author LXM
 * @Title: LDA4News
 * @Description: 该类用于新闻数据处理与LDA主题模型处理事宜
 * @date 2018/3/5下午1:53
 */
public class LDA4News {


    private Logger logger = LoggerFactory.getLogger(LDA4News.class);

    /**
     * 训练数据
     *
     * @param newsFileDirPath
     * @param modelSaveFilePath
     * @param themeCount
     * @throws IOException
     */
    public void trainModel(String newsFileDirPath, String modelSaveFile, int themeCount) throws IOException {
        //训练语料，产生 LDA 模型
        HanLDA.train(newsFileDirPath, themeCount, modelSaveFile, true);

    }

    /**
     * 预测主题
     *
     * @param textPath  分词后的文档路径
     * @param modelPath
     * @return
     */
    public List<LDATheme> inference(String textPath, String modelPath) throws IOException {
        logger.info("预测主题:" + textPath);
        List<LDATheme> themes = HanLDA.inference(modelPath, textPath);
        return themes;

    }

}
